package com.example.demo.dao.people;

import com.example.demo.model.people.Provider;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface ProviderDAO {
    //    一对一
    @Select("select * from provider where id=#{provider_id}")
    List<Provider> getByProviderId(Integer provider_id);

    //查询全部
    @Select("select * from provider")
    List<Provider> selectAll();
    //添加
    @Insert("insert into provider(providername,address,telephone,zip,connectionperson,phone,bank,account,email,fax)" +
            " values(#{providername},#{address},#{telephone},#{zip},#{connectionperson},#{phone},#{bank},#{account},#{email},#{fax})")
    Integer addProvider(Provider provider);
    //    删除
    @Delete("delete from provider where id=#{id}")
    Integer deleteById(Integer id);
    //    修改
    @Update("update provider set providername=#{providername},address=#{address},telephone=#{telephone},zip=#{zip},connectionperson=#{connectionperson}," +
            "phone=#{phone},bank=#{bank},account=#{account},email=#{email},fax=#{fax} where id=#{id}")
    Integer updateById(Provider provider);

    //  模糊查询
    @Select("<script>"+
            "select * from provider" +
            "<where>"+
            "<if test=\"providername !=null or providername != ''\">"+
            "and providername like CONCAT('%',#{providername},'%')"+
            "</if>"+
            "<if test=\"connectionperson !=null or connectionperson != ''\">"+
            "and connectionperson like CONCAT('%',#{connectionperson},'%')"+
            "</if>"+
            "<if test=\"phone !=null or phone != ''\">"+
            "and phone like CONCAT('%',#{phone},'%')"+
            "</if>"+
            "</where>"+
            "</script>")
    public List<Provider> findProvider(String  providername,String  connectionperson,String  phone);

}
